package com.jcfk.eam.controller.main;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.*;

import com.jcfk.eam.domain.dto.main.EamAssetMigrationApplyDTO;
import com.jcfk.eam.domain.query.main.EamAssetMigrationApplyQuery;
import com.jcfk.eam.domain.query.main.EamInspectionPlanQuery;
import com.jcfk.eam.service.main.EamAssetMigrationApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 资产迁移申请
 *
 * @author yrl
 * @email 
 * @date 2025-06-20
 */
@Api(tags = {"资产迁移申请管理"})
@RestController
@RequestMapping("eamassetmigrationapply")
public class EamAssetMigrationApplyController {
    @Autowired
    private EamAssetMigrationApplyService eamAssetMigrationApplyService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamAssetMigrationApplyQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询资产迁移申请")
    @PostMapping("/queryByPage")
    public RetPage<EamAssetMigrationApplyDTO> queryByPage(@RequestBody ReqPageParam<EamAssetMigrationApplyQuery> requestParam) {
        //设置默认排序
        if(requestParam.getSort().getOrderItem()==null){
            ReqSortParam<EamAssetMigrationApplyQuery> sortParam=new ReqSortParam();
            sortParam.setColumn("lastUpdateTime");
            sortParam.setOrderBy("desc");
            requestParam.setSort(sortParam);
        }

        DataPage<EamAssetMigrationApplyDTO> page = new DataPage<EamAssetMigrationApplyDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamAssetMigrationApplyDTO.class);
        page = eamAssetMigrationApplyService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  资产迁移申请
     * 根据id 查询详情
     */
    @ApiOperation("查询资产迁移申请")
    @GetMapping("/get/{id}")
    public RetResult<EamAssetMigrationApplyDTO> get(@PathVariable("id") String id) {
            EamAssetMigrationApplyDTO item = eamAssetMigrationApplyService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理资产迁移申请
     */
    @ApiOperation("保存资产迁移申请")
    @PostMapping("/save")
    @RequestLogHeader(modular = "资产迁移申请管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamAssetMigrationApplyDTO eamAssetMigrationApply) {
        // 数据校验
        RetResult ret = eamAssetMigrationApplyService.isValid(eamAssetMigrationApply);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamAssetMigrationApply.getId())){
            // 新增
            eamAssetMigrationApplyService.insert(eamAssetMigrationApply);
        } else{
            // 更新
            eamAssetMigrationApplyService.update(eamAssetMigrationApply);
        }
        return RetResult.ok();

    }

    /**
     * 审核确认资产迁移申请
     */
    @ApiOperation("审核确认资产迁移申请")
    @PostMapping("/confirm")
    @RequestLogHeader(modular = "资产迁移申请管理", businessType = "保存")
    public RetResult<?> confirm(@RequestBody @Valid EamAssetMigrationApplyDTO eamAssetMigrationApply) {
        // 更新
        eamAssetMigrationApplyService.confirm(eamAssetMigrationApply);

        return RetResult.ok();

    }

    /**
     *  批量删除资产迁移申请
     */
    @ApiOperation("批量删除资产迁移申请")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "资产迁移申请管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamAssetMigrationApplyDTO eamAssetMigrationApply) {
        return RetResult.ok(eamAssetMigrationApplyService.logicDeleteList(eamAssetMigrationApply));
    }





    /**
     *  删除资产迁移申请
     */
    @ApiOperation("删除资产迁移申请")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "资产迁移申请管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamAssetMigrationApplyService.deleteItem(id);
        return RetResult.ok();
    }


    /**
     *  关闭资产迁移申请
     */
    @ApiOperation("关闭资产迁移申请")
    @PostMapping("/closeItem/{id}")
    @RequestLogHeader(modular = "资产迁移申请管理", businessType = "删除")
    public RetResult<?> closeItem(@PathVariable("id") String id) {
        eamAssetMigrationApplyService.closeItem(id);
        return RetResult.ok();
    }
}
